﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Unity
{
    public class Coin
    {
        private string coinType;
        private string location;
        private int coinQuantity = 5;

        public string CoinType
        {
            set
            {
                coinType = value;
            }
            get
            {
                return coinType;
            }
        }

        public string Location
        {
            set
            {
                location = value;
            }
            get
            {
                return location;
            }
        }

        private CoinProbability coinProb;

        public void InitializeCoin()
        {
            coinProb = new CoinProbability();
            coinProb.InitializePlatformCoinType();
            coinProb.InitializePlatformLocation();
        }

        public List<Coin> CreateCoins(int coinCount)
        {
            return coinProb.CreateCoins(coinCount);
        }

        public List<Coin> GetCoinItems()
        {
            List<Coin> coinSelected = new List<Coin>();
            for (int iCount = 0; iCount < coinQuantity; iCount++)
            {
                Coin item = CoinCreationScript.items.First();
				CoinCreationScript.items.Remove(item);
                coinSelected.Add(item);
            }

            return coinSelected;
        }
    }

    public class CoinProbability
    {
        private ProbabilitySelection probSelectionCoinType;
        private double coinType = 0.995;
        private double diamondType = 0.005;

        private ProbabilitySelection probSelectionLocation;
        private double firstLocation = 0.2;
        private double secondLocation = 0.2;
        private double thirdLocation = 0.2;
        private double fourthLocation = 0.2;
        private double fifthLocation = 0.2;

        public ProbabilitySelection ProbSelectionCoinType
        {
            set
            {
                probSelectionCoinType = value;
            }
            get
            {
                return probSelectionCoinType;
            }
        }

        public ProbabilitySelection ProbSelectionLocation
        {
            set
            {
                probSelectionLocation = value;
            }
            get
            {
                return probSelectionLocation;
            }
        }

        public void InitializePlatformCoinType()
        {
            probSelectionCoinType = new ProbabilitySelection();
            probSelectionCoinType.CreateProbObjectForList(1, "1", coinType);
            probSelectionCoinType.CreateProbObjectForList(2, "2", diamondType);            
        }

        public void InitializePlatformLocation()
        {
            probSelectionLocation = new ProbabilitySelection();
            probSelectionLocation.CreateProbObjectForList(1, "1", firstLocation);
            probSelectionLocation.CreateProbObjectForList(2, "2", secondLocation);
            probSelectionLocation.CreateProbObjectForList(3, "3", thirdLocation);
            probSelectionLocation.CreateProbObjectForList(4, "4", fourthLocation);
            probSelectionLocation.CreateProbObjectForList(5, "5", fifthLocation);
        }

        public List<Coin> CreateCoins(int platformCount)
        {
            List<Coin> coins = new List<Coin>();
            Random rnd = new Random();
            for (int iCount = 0; iCount < platformCount; iCount++)
            {
                Coin cn = new Coin();
                cn.CoinType = probSelectionCoinType.RandomizeProbabilitySelection(rnd);
                if (cn.CoinType == "2")
                {
                    
                }
                cn.Location = probSelectionLocation.RandomizeProbabilitySelection(rnd);
                coins.Add(cn);
            }
            return coins;
        }
    }
}
